
#include <vector>
#include <algorithm>
#include <numeric>
#include <ranges>

class Student {
    public: 
        int age;
        double gpa;
};


void test_case1() {
    std::vector<Student> students;
    std::vector<Student> selected;

    std::copy_if(students.begin(), students.end(), std::back_inserter(selected),
                [](const Student& student) {
                return student.age >= 21 && student.age <= 25 && student.gpa >= 3.5;
                });
    
    double s = std::accumulate(
        selected.begin(), selected.end(), 0.0,
        [](double sum, const Student& student) { return sum + student.gpa; });

}

void test_case2() {
    //https://en.cppreference.com/w/cpp/ranges
    std::vector<Student> students;
    double s = 0.0;
    for (const auto& student :
        students | std::views::filter([](const auto& s) {
            return s.age >= 21 && s.age <= 25 && s.gpa >= 3.5;
        }) | std::views::transform([](const auto& s) { return s.gpa; })) {
        s += student;
    }
}

int main() {

    test_case1();
    test_case2();

    return 0;
}